package com.example.tool.adapter;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

/**
 *@describe：引导页adapter
 *@author liyou
 *@time 2017/11/2 16:49
 */
public class ViewPagerAdapter extends PagerAdapter {

    //界面列表
    private ArrayList<View> views;

    public ViewPagerAdapter(ArrayList<View> views) {
        this.views = views;
    }

    /**
     * 获得当前界面数
     *
     * @return
     */
    @Override
    public int getCount() {
        if (views != null) {
            return views.size();
        } else {
            return 0;
        }
    }

    /**
     * 判断是否由对象生成界面
     *
     * @param view
     * @param object
     * @return
     */
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager) container).removeView(views.get(position));
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = views.get(position);
        ViewGroup.LayoutParams param = container.getLayoutParams();
        param.height = 10000;
        container.setLayoutParams(param);
        ((ViewPager) container).addView(view, 0);
//
//
////        param.height = 100000;
//        view.setLayoutParams(param);
//        view.setBackgroundColor(Color.BLUE);
        return view;
    }
}
